package gui.visu.listeners;

import gui.visu.dialogs.JDialogAddDisplayDataAtPosition;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import controls.DataControl;
import controls.visu.A_DisplayDataControl;
import data.Constants;

/**
 * @author Charles Perin
 * 29 mars 2011
 * LIMSI - INRIA Rennes
 * charles.perin@free.fr
 *
 */
public class ListenerAddDisplayDataInSpecificPositionOkButton implements ActionListener{

	private JDialogAddDisplayDataAtPosition parent;
	
	public ListenerAddDisplayDataInSpecificPositionOkButton(JDialogAddDisplayDataAtPosition parent){
		this.setParent(parent);
	}

	public void actionPerformed(ActionEvent arg0) {
		System.out.println("data="+parent.getSelectedLabel().getText());
		System.out.println("color="+parent.getColorDisplayData());
		System.out.println("pos="+parent.getPositionSlider().getValue());
		if (parent != null &&parent.getSelectedLabel() != null && parent.getColorDisplayData()!=null) {
			DataControl dataControl = parent.getDataControl();
			A_DisplayDataControl addedDisplayData = 
				dataControl.getDisplayDataList().getDisplayDataFromName(parent.getSelectedLabel().getText());
			addedDisplayData.setDisplayDataColor(new Color(
					parent.getColorDisplayData().getRed(),
					parent.getColorDisplayData().getGreen(),
					parent.getColorDisplayData().getBlue(),
					Constants.DISPLAY_DATA_DEFAULT_TRANSPARENCY));
			dataControl.getDisplayDataList().addDisplayData(addedDisplayData, parent.getPositionSlider().getValue());
			dataControl.updateVisuPane();
		}
		parent.getParent().setEnabled(true);
		parent.dispose();
	}

	public void setParent(JDialogAddDisplayDataAtPosition parent) {
		this.parent = parent;
	}

	public JDialogAddDisplayDataAtPosition getParent() {
		return parent;
	}

}
